import {createRouter, createWebHistory} from 'vue-router'
import blogStore from "@/stores/blog.js";


const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes: [

        {
            path: '/',
            name: 'about',
            component: () => import('@/views/home/home.vue')
        },
        {
            path: '/login',
            name: 'login',
            component: () => import('@/views/login/login.vue')
        },
        {
            path: '/admin',
            name: 'admin',
            /*添加布局容器*/
            component: () => import('@/layout/admin.vue'),
            children: [
                /*加载子页面*/
                {
                    path: '',
                    name: 'admin',
                    component: () => import('@/views/admin/admin.vue'),
                    meta: {
                        key: '首页',
                        auth: true
                    }
                },
                {
                    path: 'user',
                    name: 'user',
                    component: () => import('@/views/admin/user.vue'),
                    meta: {
                        key: '用户',
                        auth: true
                    }
                },
                {
                    path: 'article',
                    name: 'article',
                    component: () => import('@/views/admin/article.vue'),
                    meta: {
                        key: '文章',
                        auth: true
                    }
                },
                {
                    path: 'sort',
                    name: 'sort',
                    component: () => import('@/views/admin/sort.vue'),
                    meta: {
                        key: '分类',
                        auth: true
                    }
                },
                {
                    path: 'set',
                    name: 'set',
                    component: () => import('@/views/admin/set.vue'),
                    meta: {
                        key: '设置',
                        auth: true
                    }
                },
            ]
        },


    ]
})
/* 当前面包屑的显示的页面*/
router.afterEach((to, from) => {
    const store = blogStore()
    if (to.meta.key) {
        store.key = to.meta.key

    }
})
export default router
